﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace QuanLyKhoThucPham
{
    public partial class usThucPham : UserControl
    {
        public usThucPham()
        {
            InitializeComponent();
        }
        public void LoadThucPham()
        {
            DataTable dt = new DataTable();
            busThucPham TPBUS = new busThucPham();
            dt = TPBUS.LoadThucPham();
            dgvThucPham.DataSource = dt;
        }
        public void LoadNhaCungCap()
        {
            DataTable dt = new DataTable();
            busNhaCungCap NCCBUS = new busNhaCungCap();
            dt = NCCBUS.LoadNhaCungCap();
            cbbNCC.DataSource = dt;
            cbbNCC.ValueMember = "Ma_NCC";
            cbbNCC.DisplayMember = "Ten_NCC";
        }
        public void LoadDonViTinh()
        {
            DataTable dt = new DataTable();
            busDonViTinh dvBUS = new busDonViTinh();
            dt = dvBUS.LoadDonViTinh();
            cbbDVT.DataSource = dt;
            cbbDVT.ValueMember = "Ma_Dv";
            cbbDVT.DisplayMember = "Ten_Dv";
        }
        private void usThucPham_Load(object sender, EventArgs e)
        {
            LoadThucPham();
            LoadNhaCungCap();
            LoadDonViTinh();
        }

        private void btnThemTP_Click(object sender, EventArgs e)
        {
            busThucPham tpBUS = new busThucPham();
            dtoThucPham tpDTO = new dtoThucPham();
            tpDTO.Ten_TP = txtTenTP.Text;
            tpDTO.SoLuong =Convert.ToInt32(txtSoLuong.Text);
            tpDTO.DonGia = Convert.ToInt32(txtDonGia.Text);
            tpDTO.HSD =Convert.ToDateTime(dtHSD.Text);
            tpDTO.Ma_NCC = Convert.ToInt32(cbbNCC.SelectedValue);
            tpDTO.Ma_DViTinh = Convert.ToInt32(cbbDVT.SelectedValue);
            tpBUS.AddThucPham(tpDTO);
            this.usThucPham_Load(sender,e);
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {

        }
   
    }
}
